{extend name='layout/base' /}
{block name='title'}仓库管理{/block}
{block name='pageTitle'}
<div class="page-title">
    <div class="breadcrumb-env pull-left">
        <ol class="breadcrumb bc-1">
            <li>
                <a href="{:url('Index/index')}"><i class="fa-home"></i>首页</a>
            </li>
            <li>
                <a href="javascript:;">基本设置</a>
            </li>
            <li class="active">
                <strong>仓库管理</strong>
            </li>
        </ol>
    </div>
</div>
{/block}
{block name='content'}
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <!--统计总数和添加按钮-->
            <div class="panel-heading btn-toolbar">
                <div class="btn-group focus-btn-group pull-right">
                    <button class="btn btn-default btn-primary" onclick="showAjaxModal();">
                        <span class="fa-plus"></span> 添 加
                    </button>
                </div>
                <div class="btn-group dropdown-btn-group pull-left">
                    <button class="btn btn-default btn-primary">
                        <span class="fa-database"></span>&nbsp;&nbsp;&nbsp;&nbsp;共有<span style="font-weight:">&nbsp;{$count}&nbsp;</span>个仓库
                    </button>
                </div>
            </div>
            <div class="panel-body">
                <!-- searach -->
                <div class="btn-toolbar">
                    <form action="" method="get" class="form-inline" style="margin-bottom:15px;" class="search-tool">
                        <span>
                            <label class="control-label">仓库名称</label>
                            <input type="text" class="form-control" placeholder="仓库名称" name="name" value="{$Request.get.name}">
                        </span>

                        <span style="margin-left: 15px;">
                            <label class="control-label">仓库状态</label>
                            <select class="form-control" name="status">
                                <option value="-1"
                                        {eq name="Request.get.status" value="-1"} selected="selected" {/eq}
                                >全部</option>
                                <option value="1"
                                        {eq name="Request.get.status" value="1"} selected="selected" {/eq}
                                >正常</option>
                                <option value="0"
                                        {eq name="Request.get.status" value="0"} selected="selected" {/eq}
                                >废弃</option>
                            </select>
                        </span>

                        <span style="margin-left: 15px;">
                            <button class="btn btn-default btn-primary" type="submit" style="margin-top:10px;">
                                <span class="fa-search"></span> 搜 索
                            </button>
                        </span>
                    </form>
                </div>
                <!-- searach -->
                <table cellspacing="0" class="table table-small-font table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>名称</th>
                        <th>联系人</th>
                        <th>电话</th>
                        <th>状态</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name='list' id='data'}
                    <tr>
                        <td> {$data.name} </td>
                        <td> {$data.contact} </td>
                        <td> {$data.phone} </td>
                        <td> {$data.status==1?'正常':'废弃'} </td>
                        <td> {$data->add_time} </td>
                        <td>
                            <a href="javascript:;"
                               class="btn btn-secondary btn-sm btn-icon icon-left"
                               onclick="editAjaxModal('{:url('/base/Storage/edit/id/'.$data->id)}')" >
                                编辑
                            </a>
                            <a ref="javascript:;" class="btn btn-danger btn-sm btn-icon icon-left"
                               onclick="showDelModal('{$data.id}')">
                                删除
                            </a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <!--分页-->
                <ul class="pagination no-margin pull-right">
                    {$list|raw}
                </ul>
                <!--分页 end-->
            </div>
        </div>
    </div>
</div>
{/block}
{block name='modal'}
<!-- ****************************************************************************** -->
<!--Modal add (Ajax Modal)-->
<div class="modal fade" id="modal-add">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">添加仓库</h4>
            </div>

            <div class="modal-body">
                Content is loading...
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info" onclick="add_from()">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- Modal edit (Ajax Modal)-->
<div class="modal fade" id="modal-edit">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑仓库</h4>
            </div>

            <div class="modal-body">
                Content is loading...
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info" onclick="edit_from()">确定</button>
            </div>
        </div>
    </div>
</div>
<!--Modal delete (Ajax Modal)-->
<div class="modal fade" id="modal-del">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">删除仓库</h4>
            </div>

            <div class="modal-body">
                您确定要删除这个仓库吗？
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info" onclick="del_from()">确定</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //add
    function showAjaxModal(){
        jQuery('#modal-add').modal('show', {backdrop: 'static'});

        jQuery.ajax({
            url: "{:url('Storage/create')}",
            success: function(response)
            {
                jQuery('#modal-add .modal-body').html(response);
            }
        });
    }

    function add_from(){
        var res = $(".add-form").serializeArray();

        $.post("{:url('Storage/save')}", res,function(data){
            if( data.error>0 ){
                toastr.error( data.msg );
            }else{
                toastr.success( data.msg );
                jQuery('#modal-add').modal('hide');
                location.reload();
            }
        }, "json");

    }

    //edit
    function editAjaxModal(url){
        jQuery('#modal-edit').modal('show', {backdrop: 'static'});

        jQuery.ajax({
            url: url,
            success: function(response)
            {
                jQuery('#modal-edit .modal-body').html(response);
            }
        });
    }
    function edit_from(){
        var res = $(".edit_from").serializeArray();

        $.post("{:url('Storage/update')}", res,function(data){
            if( data.error>0 ){
                toastr.error( data.msg );
            }else{
                toastr.success( data.msg );
                jQuery('#modal-edit').modal('hide');
                location.reload();
            }
        }, "json");

    }

    //del
    var delId = -1;
    function showDelModal(id) {
        jQuery('#modal-del').modal('show', {backdrop: 'static'});
        delId = id;
    }

    function del_from(){
        $.post("{:url('Storage/delete')}", {id:delId},function(data){
            if( data.error>0 ){
                toastr.error( data.msg );
            }else{
                toastr.success( data.msg );
                location.reload();
            }
        }, "json");
    }
</script>
{/block}